package com.src.myapplication.widget;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ImageView;

import com.src.myapplication.MainActivity;
import com.src.myapplication.R;
import com.src.myapplication.SimPAcitvity;

import java.lang.ref.WeakReference;

/**
 * Created by Administrator on 2016/9/4.
 */
public class Splash extends Activity {
    private Handler handler;
    private boolean isFirstIn = false;
    private Intent intent;
    private static final long SPLASH_DISPLAY_LENGHT = 2000;
    private MyHanlder mHandler = new MyHanlder(this);
    private ImageView mView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashactivity);
        mView= (ImageView) findViewById(R.id.iv);
        mView.setVisibility(View.VISIBLE);
        SharedPreferences   preferences = getSharedPreferences("count", MODE_APPEND);
        int count = preferences.getInt("count", 0);
        star();
        mView.setVisibility(View.GONE);
        //判断程序与第几次运行，如果是第一次运行则跳转到引导页面
        if (count == 0) {
           intent = new Intent(Splash.this,SimPAcitvity.class);
            finish();
        }else {
            intent = new Intent(Splash.this,MainActivity.class);
        }
        startActivity(intent);
        SharedPreferences.Editor editor = preferences.edit();
        //存入数据
        editor.putInt("count", ++count);
        //提交修改
        editor.apply();
        finish();
    }
   public static class  MyHanlder extends Handler {
       private WeakReference<Splash> msplsh =null;
       MyHanlder(Splash splash){
           msplsh=new WeakReference<Splash>(splash);
       }

       @Override
       public void handleMessage(Message msg) {
           super.handleMessage(msg);
           Splash splash = msplsh.get();
           if(splash!=null){
               switch (msg.what){
                   case 1:

                       break;
                   case 2:
                       break;
               }
           }
       }
   }

    public void star(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                Message obtain = Message.obtain();
                obtain.what =1;
                mHandler.sendMessageDelayed(obtain,3000);

            }
        }).start();
    }

}
